package cn.edu.nuc.onlinestore.util;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ConnectException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

import cn.edu.nuc.onlinestore.vo.Person;

public class Socketutil {
	
	
	public boolean userSocket(String select,String username,String password){
		Person p = null;
		Socket sk;
		
		try {
			String b=select+"@"+username+"@"+password;
			 sk = new Socket("127.0.0.1",8080);
			
			DataOutputStream out=new DataOutputStream(sk.getOutputStream());
			out.writeUTF(b);
			
			out.flush();
			
			DataInputStream in=new DataInputStream(sk.getInputStream());
			//BufferedReader reader = new BufferedReader(new InputStreamReader(sk.getInputStream()));
			boolean t= in.readBoolean();
			
			System.out.println("t:" + t);
			out.close();
			in.close();
			sk.close();
			
			return t;
			
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}catch (ConnectException e){
			JOptionPane.showMessageDialog(null, "服务端未启动", "alert", JOptionPane.ERROR_MESSAGE); 
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return false;
		
	}


}
